<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta charset="utf-8" />
	<title></title>
	<link href="../css/bootstrap.min.css" rel="stylesheet">
	<link href="../css/bootstrap-select.css" rel="stylesheet">
    <link rel="stylesheet" href="../css/bootstrap-datetimepicker.min.css">
	<link href="../css/font-awesome.min.css" rel="stylesheet">
	<link href="../css/JyyCommon.css" rel="stylesheet">
	<link href="../css/JyyTable.css" rel="stylesheet">
	<link href="../css/JyyTree.css" rel="stylesheet">
	<link href="../css/JyyMsgBox.css" rel="stylesheet">
	<script type="text/javascript" src="../js/jquery-3.2.1.js"></script>
	<script type="text/javascript" src="../js/jquery.form.min.js"></script> 
	<script type="text/javascript" src="../js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-datetimepicker.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-paginator.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-select.js"></script>
	<script type="text/javascript" src="../js/jyy_modal.js"></script>
	<script type="text/javascript" src="../js/JyyCommon.js"></script>
	<script type="text/javascript" src="../js/JyyTable.js"></script>
	<script type="text/javascript" src="../js/JyyTree.js"></script>
	<script type="text/javascript" src="../js/JyyMsgBox.js"></script>
	<script type="text/javascript" src="../js/JyyLoading.js"></script>
	<style>
	.heidenbt{
		display: none
	}
	.tableA {
		cursor: pointer;
	}
</style>
	<script type="text/javascript">
		var table = null;
		var scheme = null;
		var unitid = unescape(getQueryString("unitid"));
		var type = unescape(getQueryString("type"))||'';
		var code = 0;
		if(type == "指定出力"){
			code = 1852;
		}else if(type == "三段式出力"){
			code = 1853;
		} else if(type == "指定电量") {
			code = 1854;
		}
		$(function(){
			setlabel(type);
			JyyLoading.start();
			$.when(getTableData(code)).done(function(tableData){
				if(table == null){
					table = JyyTable.init("table", tableData, {position:"absolute",top:"50px",left:"5px",right:"5px",bottom:"0px",overflow:"hidden"}, onTableEvent);
				}else{
					table.refresh(tableData);
				}
				JyyLoading.end();
			});
		})
		function setlabel(type){
			$("#daochu").addClass("heidenbt")
			$("#daoru").addClass("heidenbt")
			$("#xinzeng").addClass("heidenbt")
			$("#shanchu").addClass("heidenbt")
			$("#xianshi").addClass("heidenbt")
			var label = "";
			if(type == "指定出力"){
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				$("#xinzeng").removeClass("heidenbt")
				$("#shanchu").removeClass("heidenbt")
				label = "单位：MW";
			}else if(type == "三段式出力"){
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				$("#xinzeng").removeClass("heidenbt")
				$("#shanchu").removeClass("heidenbt")
				label = "单位：MW";
			} else if(type == "指定电量") {
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				$("#xinzeng").removeClass("heidenbt")
				$("#shanchu").removeClass("heidenbt")
			}
			$("#unitTitle").text(label);
		}
		
		function onTableEvent(type, value){
			console.log("onTableEvent");
			var checkArr = [];
			if(code == "1852" || code == "1853") {
				checkArr = [1];
			} else if(code == "1854") {
				checkArr = [1,2];
			}
			if(type == "insertBefore"){
				console.log("insertBefore");
				//核查数据正确性
				for(var a = 0 ; a < value[1].length; a++){
					if(table.config.hideCols.indexOf(a) <= -1){
						if(JyyCommon.isEmpty(value[1][a])){
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]不可为空",type:"warning"}).on(function (e) {});
							return false;
						}else if((!JyyCommon.isObject(value[1][a]) && value[1][a].indexOf("请选择")>-1) || value[1][a] == " "){
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]下拉框未做选择",type:"warning"}).on(function (e) {});
							return false;
						}else if(JyyCommon.isObject(value[1][a]) && JyyCommon.isEmpty(value[1][a].name)){
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]不可为空",type:"warning"}).on(function (e) {});
							return false;
						} else if (checkArr.indexOf(a) != -1 && value[1][a].length != 8) {
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]长度不是8位",type:"warning"}).on(function (e) {});
							return false;
						}
					}
				}
				return true;
			} else if(type == "data"){
				JyyLoading.start();
				var url = "../pv/page/check/"+code;
 				 $.ajax({
		            type:"POST",
		            url: url,
		            data:{"value":JSON.stringify(value),"unitid":unitid,"projectid":parent.parent.planId},
		            success:function(data){
		            	var pageSize = table.config.page.option.pageSize;
						$.when(getTableData(code, 1, pageSize, null)).done(function(tableData){
							table.refresh(tableData);
							JyyLoading.end();
						});
		            }
		        }); 
			} else if(type == "page"){
				console.log("page");
				JyyLoading.start();
				$.when(getTableData(code, value.currentPage, value.pageSize, null)).done(function(tableData){
					table.refresh(tableData);
					JyyLoading.end();
				});
			}
		}
		//新增按钮
		function addRow(){
			table.addRow();
		}
		//修改按钮
		function updateRow(){
			table.updateRows();
		}
		//取消修改按钮
		function cancelRow(){
			table.cancelRow();
		}
		//删除按钮
		function deleteRow(){
			table.deleteRows();
		}
		//保存按钮
		function saveRow(){
			table.saveRow();
		}
		//下载按钮
		function download(){
			var form = $('<form action="../pv/pageExcel/downloadExcel/'+ code +'" style="display:none" method="post">');
			var input = $('<input type="hidden" name="projectid">');
			input.attr("value",parent.parent.planId);
			form.append(input);
			if(unitid != null && unitid != "") {
				var input1 = $('<input type="hidden" name="unitid">');
				input1.attr("value",unitid);
				form.append(input1);
			}
			$("body").append(form);
			form.submit();
			form.remove();
		}
		//上传按钮
		function upload(){
			var file = document.getElementById("file");
			if(file.value.indexOf('xls')==-1){
				JyyMsgBox.alert({ title:"警告", message:"请选择正确的Excel文件",type:"warning"}).on(function (e) {});
				return;
			}
			JyyLoading.start();
			var fileObj = file.files[0];
			var url = "../pv/pageExcel/loadExcel/"+code;

			var form = new FormData();
			form.append("file",fileObj);
			form.append("projectid",parent.parent.planId);
			if(unitid != null && unitid != "") {
				form.append("unitid",unitid);
			}
			var xhr = new XMLHttpRequest();
			xhr.open("post", url, true);
			xhr.send(form);
			xhr.onreadystatechange = function(){
			    if(xhr.readyState === 4 && xhr.status === 200){
					var pageSize = table.config.page.option.pageSize;
					$.when(getTableData(code,1, pageSize,null)).done(function(tableData){
						table.refresh(tableData);
						JyyLoading.end();
					   document.getElementById("file").value=null
					});
			    }
			    if(xhr.readyState === 4 && xhr.status === 500){
			    	JyyLoading.end();
			    }
			}

		}
		//显示隐藏列按钮
		function colsState(e){
			var i = $(e).find('i');
			if($(i).is('.glyphicon-align-justify')){
				$(i).removeClass('glyphicon-align-justify')
				$(i).addClass('glyphicon-list');
				$(e).html($(e).html().replace("显示隐藏列", "隐藏默认列"));
				table.hideCols(false);
			}else{
				$(i).removeClass('glyphicon-list')
				$(i).addClass('glyphicon-align-justify');
				$(e).html($(e).html().replace("隐藏默认列", "显示隐藏列"));
				table.hideCols(true);
			}
		}
		//查询
		function select(){
			var currentPage = 1;
			var pageSize = table.config.page.option.pageSize;
			
			JyyLoading.start();
			$.when(getTableData(code, currentPage, pageSize, null)).done(function(tableData){
				table.refresh(tableData);
				JyyLoading.end();
			});
		}
		//重置
		function reset(){
			var currentPage = 1;
			var pageSize = table.config.page.option.pageSize;
			
			JyyLoading.start();
			$.when(getTableData(code, currentPage, pageSize, null)).done(function(tableData){
				table.refresh(tableData);
				JyyLoading.end();
			});
		}
		
		function getTableData(code, currentPage, pageSize, keyword){
			var defer = $.Deferred();
			var result = null;
			var url = "../pv/page/pageInfo/"+code;

			$.ajax({
				dataType: "json",
				async:true,
				data:{"pagenow":currentPage,"pagenum":pageSize,"unitid":unitid,"keyword":keyword,"projectid":parent.parent.planId},
				url: url
			}).done(function(res) {
				var sts=eval("("+res+")");
				result = sts;
				defer.resolve(sts);
			});
			return defer.promise();
		}
		function getQueryString (name){
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			return r ? unescape(r[2]) : null;
		}
	</script>
</head>
<body style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;">
	<div id="operate" style="position: absolute;top: 0px;left: 5px;right: 0px;height: 50px;">
		<div id="alltitle" style="width: 100%;display: none;margin: 5px;"><span id="managerTitle"></span><span id="titleName"></span></div>
		<div class="col-md-12" style="position: absolute;top: 10px;padding-left: 5px;padding-right: 5px;">
			
			<button id="xinzeng" class="btn btn-info btn-sm" onclick=addRow()><i class="fa fa-plus"></i>新增</button>
			<button id="xiugai"  class="btn btn-info btn-sm" onclick=updateRow()><i class="glyphicon glyphicon-pencil"></i>修改</button>
			<button id="quxiao"  class="btn btn-info btn-sm" onclick=cancelRow()><i class="glyphicon glyphicon-share-alt"></i>取消修改</button>
			<button id="shanchu"  class="btn btn-info btn-sm" onclick=deleteRow()><i class="glyphicon glyphicon-remove"></i>删除</button>
			<button id="baocun"  class="btn btn-info btn-sm" onclick=saveRow()><i class="glyphicon glyphicon-saved"></i>保存</button>
			<button id="daochu"  class="btn btn-info btn-sm" onclick=download()><i class="glyphicon glyphicon-download"></i>导出Excel</button>
			<button id="daoru"  class="btn btn-info btn-sm" onclick=$("#file").click();><i class="glyphicon glyphicon-upload"></i>导入Excel</button>
			<button id="xianshi"  class="btn btn-info btn-sm" onclick=colsState(this)><i class="glyphicon glyphicon-align-justify"></i>显示隐藏列</button>
			
			<button id="reset" class="btn btn-info btn-sm" style="float: right;display: none;" onclick=reset()>重置</button>
			<button id="select" class="btn btn-info btn-sm" style="float: right;margin-right: 5px;display: none;" onclick=select()>查询</button>

			<div class="col-sm-3" style="float: right;width:170px;padding-left: 0px;display: none;">
            	<input id="term" type="text" class="form-control"style="width:150px;height:30px;font-size: 12px;" id="txt_search_departmentname">
				<select class="form-control" style="width:150px;height:30px;font-size: 12px;display: none;" id="selectSearch"></select>
            </div>
			<label id="unitTitle" class="control-label col-sm-1" style="float: right;margin-top: 7px;padding: 0px;width: 60px;font-weight: normal;"></label>
		
			<input type="file" id="file" name="file" onchange="upload(this)" style="display:none"/>
		</div>
	</div>
	<div id="table"></div>
	<form action='../pv/page/pageInfo/201' method='post' id='form1' enctype="multipart/form-data">
		<input type="file" id="allDownload" name="allDownload" onchange="allDownloads(this)" style="display:none"/>
		<input type="hidden" name="schemeid">
	</form>
	<form action='../pv/page/pageInfo/202' method='post' id='form2'>
		<input type="hidden" name="schemeid">
	</form>
</body>
</html>